package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity1 extends AppCompatActivity {
    private static final String TAG = "main2";
    EditText input;
    TextView output;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.jifenqi);
    }

    public void myClick(View v) {
        input = findViewById(R.id.inp1);
        String str1 = input.getText().toString();
        float aa1 = Float.parseFloat(str1);
        input = findViewById(R.id.inp2);
        String str2 = input.getText().toString();
        float aa2 = Float.parseFloat(str2);
        double result = aa2 / (aa1 * aa1);
        output = findViewById(R.id.jieguo);
        output.setText("结果为" + String.format("%.2f",result));
        if (result < 18.5) {
            output.append("\n体重过低,建议多吃点");
        }
        if (result >= 18.5 && result < 24) {
            output.append("\n体重正常，身体健康！");
        }
        if (result >= 24 && result < 28) {
            output.append("\n超重，建议优化饮食体系");
        }
        if (result >= 28) {
            output.append("\n肥胖，要开始减肥了哦");
        }
    }
}


